﻿using System;
using AMM.Business;
using AMM.Model;
using AMM.Model.Project;

namespace AMM.UserControls {
    public partial class MaterialSearchControl : BaseSearchControl {

        public override BaseSearchModel GetSearchModel() {
            int currencyValue = Convert.ToInt32(this.cmbMaterialType.SelectedValue);
            int enabledValue = Convert.ToInt32(this.cmbIsEnabled.SelectedValue);

            MaterialSearchModel searchResult = new MaterialSearchModel();
            searchResult.Code = this.tbCode.Text;
            searchResult.Name = this.tbName.Text;
            searchResult.MaterialTypeId = currencyValue;
            searchResult.IsEnabled = Convert.ToBoolean(enabledValue);

            if (currencyValue == 0) { searchResult.MaterialTypeId = null; }
            if (enabledValue == -1) { searchResult.IsEnabled = null; }

            return searchResult;
        }

        public override void ResetSearchModel() {
            this.tbCode.Clear();
            this.tbName.Clear();
            this.cmbMaterialType.SelectedIndex = 0;
            this.cmbIsEnabled.SelectedValue = "-1";
        }

        public MaterialSearchControl() {
            this.InitializeComponent();

            this.BindBasics(this.cmbMaterialType, BasicsType.MaterialType);
            this.BindIsEnabled(this.cmbIsEnabled);
        }
    }
}
